#ifdef DEBUG
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <UIKit/UIApplication.h>
#import <LockInfo/Plugin.h>

#import "framework/FWCommon.h"
#import "framework/FWDetailListEntry.h"
#import "framework/FWDetailListSection.h"

#import "PICommon.h"
#import "PIAlarmsList.h"
#import "PIAlarm.h"
#import "PIEvent.h"
#import "PIContext.h"


@implementation PIAlarmsList

@synthesize alarms, events;


// ******************************************************************************************
#pragma mark -
#pragma mark Initialisation and object management

- (id)initWithAlarms:(NSArray*)newAlarms events:(NSArray*)newEvents
{
    if ((self = [super init])) {
        self.alarms = newAlarms;
        self.events = newEvents;
    }
    
    return self;
}

- (void)dealloc
{
    [alarms release];
    [events release];
    
    [super dealloc];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Handling user input

- (BOOL)cancelClicked:(FWApplication*)application sections:(NSArray*)sections
{
    return YES;
}


// ******************************************************************************************
#pragma mark -
#pragma mark Accessing records from the database

- (NSArray*)dataForDetailListPage:(NSObject *)page key:(NSObject*)key application:(FWApplication *)application
{  
    NSMutableArray* contents = [NSMutableArray arrayWithCapacity:alarms.count];
    
    for (PIAlarm* alarm in alarms) {
        PIEvent* event = [events piObjectForKey:alarm.key];
        
        NSString* type;
        switch (alarm.type) {
            case kPICalAlarmTypeNative:
                type = @"Native";
                break;
            case kPICalAlarmTypeExtraAlarm:
                type = @"Extra Alarm at";
                break;
            case kPICalAlarmTypeExtraReminder:
                type = @"Extra Remind at";
                break;
            case kPICalAlarmTypeAlarmIsActive:
                type = @"Alarm Active until";
                break;
            default:
                type = @"??";
                break;
        }

        NSString* name = [event title];
        if (!name)
            name = alarm.key.length > 20 ? [alarm.key substringFromIndex:alarm.key.length - 20] : alarm.key;
        
        [contents addObject:[[[FWDetailListEntry entryWithTitle:[NSString stringWithFormat:
                                                                 @"Key: %@\n"
                                                                 "Title: %@\n\n"
                                                                 "Status: %@ %@",
                                                                 alarm.key,
                                                                 name,
                                                                 type,
                                                                 FWDebugTimeStringForUTCDate(alarm.date)]]
                              withSize:[UIFont systemFontSize]]
                             withNoBold]];
    }

    return [NSArray arrayWithObject:[FWDetailListSection sectionForElements:contents]];
}

@end
#endif